package com.wsc.it.techfuser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.wsc.it.techfuser.vo.TechfuserApplyReturnRequest;
import com.wsc.it.techfuser.vo.TechfuserClassifyRequest;
import com.wsc.it.techfuser.vo.TechfuserClassifyResponse;
import com.wsc.it.techfuser.vo.TechfuserDiscountPromotionRequest;
import com.wsc.it.techfuser.vo.TechfuserEnum;
import com.wsc.it.techfuser.vo.TechfuserEvaluationRequest;
import com.wsc.it.techfuser.vo.TechfuserGoodsImgExceptionRequest;
import com.wsc.it.techfuser.vo.TechfuserGoodsRequest;
import com.wsc.it.techfuser.vo.TechfuserGoodsResponse;
import com.wsc.it.techfuser.vo.TechfuserGoodsStatusRequest;
import com.wsc.it.techfuser.vo.TechfuserOrderDetailRequest;
import com.wsc.it.techfuser.vo.TechfuserOrderRequest;
import com.wsc.it.techfuser.vo.TechfuserPickRequest;
import com.wsc.it.techfuser.vo.TechfuserResponseBase;
import com.wsc.it.techfuser.vo.TechfuserStatusApplyReturnRequest;
import com.wsc.it.techfuser.vo.TechfuserStatusOrderRequest;
import com.wsc.it.techfuser.vo.TechfuserStoreOrgRequest;
import com.wsc.it.techfuser.vo.TechfuserStoreRequest;
import com.wsc.it.techfuser.vo.TechfuserStoreResponse;

import lombok.Data;

/**
 * @description: 牵牛花api 2.3
 * @author: wsc58888
 * @create: 2022-03-14
 **/
@Data
public class TechfuserApiService {

    private String url ="http://openapi.m-glory.net";

    private String appid="";

    private String secret="";


    /**
     * 2.1 查询门店组织机构
     */
    public String getStores(TechfuserStoreOrgRequest storeOrgRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETSTORES.getUrl(), storeOrgRequest, appid, secret);
    }

    /**
     * 2.2 查询店铺信息
     */
    public TechfuserResponseBase<ArrayList<TechfuserStoreResponse>> queryStore(TechfuserStoreRequest storeRequest) {
        String responseJson = TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYSTORE.getUrl(), storeRequest, appid, secret);
        return JSON.parseObject(responseJson, new TypeReference<TechfuserResponseBase<ArrayList<TechfuserStoreResponse>>>() {
        });
    }

    /**
     * 3.1 查询商品
     */
    public String getItems(TechfuserGoodsRequest goodsRequest) {
        goodsRequest.setData_type("itemBase");
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETITEMS.getUrl(), goodsRequest, appid, secret);
    }

    /**
     * 3.2 查询门店商品列表
     */
    public TechfuserResponseBase<ArrayList<TechfuserGoodsResponse>> getOrgItems(TechfuserGoodsRequest goodsRequest) {
        goodsRequest.setData_type("item");
        String responseJson = TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETORGITEMS.getUrl(), goodsRequest, appid, secret);
        return JSON.parseObject(responseJson, new TypeReference<TechfuserResponseBase<ArrayList<TechfuserGoodsResponse>>>() {
        });
    }

    /**
     * 3.3 查询商品价格
     */
    public String getItemPrices(TechfuserGoodsRequest goodsRequest) {
        goodsRequest.setData_type("price");
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETITEMPRICES.getUrl(), goodsRequest, appid, secret);
    }

    /**
     * 3.4 查询商品库存
     */
    public String getItemStocks(TechfuserGoodsRequest goodsRequest) {
        goodsRequest.setData_type("stock");
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETITEMSTOCKS.getUrl(), goodsRequest, appid, secret);
    }

    /**
     * 3.5 查询线上分类
     */
    public TechfuserResponseBase<ArrayList<TechfuserClassifyResponse>> findCategory(TechfuserClassifyRequest classifyRequest) {
        classifyRequest.setData_type("category");
        String responseJson = TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.FINDCATEGORY.getUrl(), classifyRequest, appid, secret);
        return JSON.parseObject(responseJson, new TypeReference<TechfuserResponseBase<ArrayList<TechfuserClassifyResponse>>>() {
        });
    }

    /**
     * 3.6 修改商品上下架状态
     */
    public String updateItemSaleStatus(TechfuserGoodsStatusRequest goodsStatusRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.UPDATEITEMSALESTATUS.getUrl(), goodsStatusRequest, appid, secret);
    }

    /**
     * 3.7 修改商品售卖状态
     */
    public String updateItemStatus(TechfuserGoodsStatusRequest goodsStatusRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.UPDATEITEMSTATUS.getUrl(), goodsStatusRequest, appid, secret);
    }

    /**
     * 3.10 请求重传商品图片接口
     */
    public String askForResendImage(TechfuserGoodsImgExceptionRequest imgExceptionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.ASKFORRESENDIMAGE.getUrl(), imgExceptionRequest, appid, secret);
    }

    /**
     * 4.1 查询单品直降促销单头
     */
    public String queryDiscountPromotionHead(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYDISCOUNTPROMOTIONHEAD.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 4.2 查询单品直降促销单明细
     */
    public String queryDiscountPromotionDetail(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYDISCOUNTPROMOTIONDETAIL.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 4.3 查询满减促销单头
     */
    public String queryFullDiscountPromotionHead(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYFULLDISCOUNTPROMOTIONHEAD.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 4.4 查询满减促销单明细
     */
    public String queryFullDiscountPromotionDetail(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYFULLDISCOUNTPROMOTIONDETAIL.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 4.5 查询有效促销单
     */
    public String queryActivePromotionCode(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.QUERYACTIVEPROMOTIONCODE.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 4.7 接收促销门店明细变更接口
     */
    public String updatePromotionItemRegionStatus(TechfuserDiscountPromotionRequest discountPromotionRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.UPDATEPROMOTIONITEMREGIONSTATUS.getUrl(), discountPromotionRequest, appid, secret);
    }

    /**
     * 5.1 接收新订单和新退单
     */
    public TechfuserResponseBase addOrder(TechfuserOrderRequest orderRequest) {
        String responseJson = TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.ADDORDER.getUrl(), orderRequest, appid, secret);
        return JSON.parseObject(responseJson, new TypeReference<TechfuserResponseBase>() {
        });
    }

    /**
     * 5.2 接收订单和退单状态
     */
    public String pushStatusOrder(List<TechfuserStatusOrderRequest> orderRequestList) {
        Map<String, List<TechfuserStatusOrderRequest>> data = new HashMap<>();
        data.put("data", orderRequestList);
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.PUSHSTATUSORDER.getUrl(), data, appid, secret);
    }

    /**
     * 5.3 接收评价信息
     */
    public String pushEvaluation(List<TechfuserEvaluationRequest> evaluationRequestList) {
        Map<String, List<TechfuserEvaluationRequest>> data = new HashMap<>();
        data.put("data", evaluationRequestList);
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.PUSHEVALUATION.getUrl(), data, appid, secret);
    }

    /**
     * 5.4 获取牵牛花订单和退单详情
     */
    public String getorderdetail(TechfuserOrderDetailRequest orderDetailRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETORDERDETAIL.getUrl(), orderDetailRequest, appid, secret);
    }

    /**
     * 5.6 获取牵牛花退单申请
     */
    public String getreturnapply(TechfuserOrderDetailRequest orderDetailRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.GETRETURNAPPLY.getUrl(), orderDetailRequest, appid, secret);
    }

    /**
     * 5.7 接收售后单申请接口
     */
    public String addApplyReturn(TechfuserApplyReturnRequest applyReturnRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.ADDAPPLYRETURN.getUrl(), applyReturnRequest, appid, secret);
    }

    /**
     * 5.8 接收退单申请单状态接口
     */
    public String pushStatusApplyReturn(TechfuserStatusApplyReturnRequest statusApplyReturnRequest) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.PUSHSTATUSAPPLYRETURN.getUrl(), statusApplyReturnRequest, appid, secret);
    }

    /**
     * 6.1 接收拣货完成消息
     */
    public String pickup(TechfuserPickRequest pickParam) {
        return TechfuserUtil.TechfuserHttpPost(url + TechfuserEnum.PICKUP.getUrl(), pickParam, appid, secret);
    }

}
